import axios from 'axios';

const state = {
  goodItems: [] 
}

const mutations = {
  UPDATE_PRODUCT_ITEMS (state, payload) {
    state.goodItems = payload;
  }
}

const actions = {
  getGoodItems ({ commit }) {
    axios.get(`goodsList`).then((response) => {
      console.log(response.data.body);
      commit('UPDATE_PRODUCT_ITEMS', response.data.body)
    });
  }
}

const getters = {
  goodItems: state => state.goodItems,
  goodItemFromId: (state) => (id) => {
    return state.goodItems.find(goodItem => goodItem.id === id)
  }
}

const goodModule = {
  state,
  mutations,
  actions,
  getters
}

export default goodModule;